<template>
  <div class="app-container">
    <el-col :span="4">
      <div class="my-div">
        <el-input v-model="appCategoryName" placeholder="应用分类" clearable size="small" prefix-icon="el-icon-search" />
      </div>

      <div class="my-div">
        <el-tree :data="appCateList" :props="defaultProps" :expand-on-click-node="false"
          :filter-node-method="filterNode" ref="tree" node-key="id" default-expand-all highlight-current
          @node-click="handleNodeClick" />
      </div>
    </el-col>

    <!--用户数据-->
    <el-col :span="20" :xs="24">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="流程名称" prop="name">
          <el-input v-model="queryParams.name" placeholder="支持模糊查询" clearable style="width: 240px"
            @keyup.enter.native="getList" />
        </el-form-item>
        <el-form-item label="流程标识" prop="key">
          <el-input v-model="queryParams.key" placeholder="流程标识" clearable style="width: 240px"
            @keyup.enter.native="getList" />
        </el-form-item>

        <el-form-item label="创建时间">
          <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
            range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
            v-hasPermi="['design:model:add']">新增</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-row :gutter="10" :span="15">
        <el-col :span="4" v-for="(o, index) in modelList" :key="index">
          <el-card class="box-card">

            <div slot="header" class="clearfix" @click="toDetail(o)">
              <span>{{o.name}}</span>
            </div>

            <div class="container">
              <div class="parent" >
                <div>
                  <el-image fit="fill" :src="modePics[index]" :preview-src-list="previewPics[index]">
                    <div slot="error" class="image-slot"> <i class="el-icon-picture-outline" /> </div>
                  </el-image>
                </div>
              </div>
            </div>


          </el-card>
        </el-col>
      </el-row>

      <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />

    </el-col>
    </el-row>


  </div>
</template>

<script>
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import IconSelect from "@/components/IconSelect";
  import {
    findActAppLabel
  } from "@/api/flowDesign/actApp";

  import {
    listModel
  } from "@/api/flowDesign/sModel";

  import {
    listImages
  } from "@/api/flowDesign/sModelVersion";

  export default {
    name: "Menu",
    components: {
      Treeselect,
      IconSelect
    },
    data() {
      return {
        // 显示搜索条件
        showSearch: true,
        //应用树查询条件
        appCategoryName: undefined,
        //应用树数据
        appCateList: [],
        //模型数据
        queryParams: {
          pageNum: 1,
          pageSize: 9,
          domain: {
            category: undefined,
          }

        },
        //应用树默认结构
        defaultProps: {
          children: 'children',
          label: 'label'
        },
        loading: false,
        modelList: [],
        dateRange: [],
        total: 0,
        modePics: [],
        previewPics:[],
      };
    },
    created() {
      this.listActAppCateGory();
      this.getList();
    },
    watch: {
      appCategoryName(val) {
        this.$refs.tree.filter(val);
      }
    },
    methods: {
      toDetail(smodel){
        let query = {"smodelId":smodel.id,"verId":smodel.lastUpdVersionId}
        console.log(query);
        this.$router.push({path: '/push/push/manage/modelDetail', query: query});
      },
      //查询数据
      getList() {
        this.loading = true;
        listModel(this.queryParams).then(res => {
          this.modelList = res.data.records;
          this.total = res.data.total;
          //查询图片
          debugger
          let vIds = [];
          this.modelList.forEach(o => {
            vIds.push(o.lastUpdVersionId);
          })
          let dataJson = {
            "ids": vIds
          };

          listImages(dataJson).then(res => {
            res.data.forEach(o => {
              this.modePics.push('data:image/jpeg;base64,' + o);
              let onePreViews = [];
              onePreViews.push('data:image/jpeg;base64,' + o);
              this.previewPics.push(onePreViews);

            });
          });

          this.loading = false;
        })
      },
      //重置收缩
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.queryParams.domain.category = undefined;
        this.getList();

      },
      //处理新增
      handleAdd() {},

      //获取到应用分类
      listActAppCateGory() {
        findActAppLabel().then(res => {
          this.appCateList = res.data;
        });
      },

      // 筛选节点
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      // 节点单击事件
      handleNodeClick(data) {
        this.queryParams.category = data.id;
      },
    }
  };
</script>

<style>
  .my-div {
    margin-left: 10px;
    /* 设置左边距为20像素 */
    margin-right: 20px;
  }
</style>
